<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="90px">
								<el-input v-model="form.sysCompanyId" type="hidden"></el-input>
								<el-form-item label="公司名" prop="companyName">
									<el-input v-model="form.companyName" placeholder="请输入公司名" clearable></el-input>
								</el-form-item>
								<el-form-item label="所在城市" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入国家城市path" clearable></el-input>
								</el-form-item>
								<el-form-item label="详细地址" prop="address">
									<el-input v-model="form.address" placeholder="请输入地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="电话" prop="phone">
									<el-input v-model="form.phone" placeholder="请输入电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮箱" prop="email">
									<el-input v-model="form.email" placeholder="请输入邮箱" clearable></el-input>
								</el-form-item>
								<el-form-item label="传真" prop="fax">
									<el-input v-model="form.fax" placeholder="请输入传真" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮编" prop="zip">
									<el-input v-model="form.zip" placeholder="请输入邮编" clearable></el-input>
								</el-form-item>
								<el-form-item label="logo" prop="logo">
									<el-input v-model="form.logo" placeholder="请输入logo图片地址 前后台使用" clearable></el-input>
								</el-form-item>
								<el-form-item label="身份证正面" prop="baImg1">
									<el-input v-model="form.baImg1" placeholder="请输入备案 法人身份证正面" clearable></el-input>
								</el-form-item>
								<el-form-item label="身份证反面" prop="baImg2">
									<el-input v-model="form.baImg2" placeholder="请输入备案 法人身份证反面" clearable></el-input>
								</el-form-item>
								<el-form-item label="营业执照" prop="baImg3">
									<el-input v-model="form.baImg3" placeholder="请输入备案 营业执照" clearable></el-input>
								</el-form-item>
								<el-form-item label="税务证" prop="baImg4">
									<el-input v-model="form.baImg4" placeholder="请输入备案 税务证" clearable></el-input>
								</el-form-item>
								<el-form-item label="对公账户" prop="dgyhDesc">
									<el-input v-model="form.dgyhDesc" placeholder="请输入对公账户信息" clearable></el-input>
								</el-form-item>
								<el-form-item label="qq" prop="qq">
									<el-input v-model="form.qq" placeholder="请输入qq" clearable></el-input>
								</el-form-item>
								<el-form-item label="前台网址" prop="frontUrl">
									<el-input v-model="form.frontUrl" placeholder="请输入前台网址" clearable></el-input>
								</el-form-item>
								<el-form-item label="备案信息" prop="rightMsg">
									<el-input v-model="form.rightMsg" placeholder="请输入备案信息" clearable></el-input>
								</el-form-item>
								<el-form-item label="服务热线" prop="hotLine">
									<el-input v-model="form.hotLine" placeholder="请输入服务热线" clearable></el-input>
								</el-form-item>
								<el-form-item label="备注" prop="msg">
									<el-input v-model="form.msg" placeholder="请输入备注" clearable></el-input>
								</el-form-item>
								<el-form-item label="状态" prop="state">
									<el-radio-group v-model="form.state">
										<p><el-radio :label="1">激活</el-radio><el-radio :label="0">失效</el-radio></p>
									</el-radio-group>
								</el-form-item>
								<el-form-item label="日期时间" prop="jfDate">
									缴费日期:{{form.jfDate}}&nbsp;&nbsp;&nbsp;&nbsp;最近缴费日期:{{form.jfLastTime}}
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import systemAPI from '@/api/system/sysCompany';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					sysCompanyId: "",
					companyName: "",
					regionPath: "",
					address: "",
					phone: "",
					email: "",
					fax: "",
					zip: "",
					logo: "",
					baImg1: "",
					baImg2: "",
					baImg3: "",
					baImg4: "",
					dgyhDesc: "",
					qq: "",
					frontUrl: "",
					rightMsg: "",
					hotLine: "",
					msg: "",
					state: "",
					jfDate: "",
					jfLastTime: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await systemAPI.sysCompany.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.sysCompanyId = data.sysCompanyId;
				this.form.parentId = data.parentId;
				this.form.companyName = data.companyName;
				this.form.regionPath = data.regionPath;
				this.form.address = data.address;
				this.form.phone = data.phone;
				this.form.email = data.email;
				this.form.fax = data.fax;
				this.form.zip = data.zip;
				this.form.logo = data.logo;
				this.form.baImg1 = data.baImg1;
				this.form.baImg2 = data.baImg2;
				this.form.baImg3 = data.baImg3;
				this.form.baImg4 = data.baImg4;
				this.form.dgyhDesc = data.dgyhDesc;
				this.form.qq = data.qq;
				this.form.frontUrl = data.frontUrl;
				this.form.rightMsg = data.rightMsg;
				this.form.hotLine = data.hotLine;
				this.form.msg = data.msg;
				this.form.state = data.state;
				this.form.jfDate = data.jfDate;
				this.form.jfLastTime = data.jfLastTime;
			}
		}
	}
</script>
<style>
</style>
